home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
pctj8407.arc
/
MATRIX.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-09-14
|
2KB
|
114 lines
PROGRAM MATRIX;
(* By Alan R. Miller *)
(* from: PASCAL PROGRAMS FOR SCIENTISTS AND ENGINEERS *)
(* (c) 1981 by Sybex, Inc. *)
CONST
RMAX = 20;
CMAX = 20;
TYPE
ARY = ARRAY[1..RMAX] OF REAL;
ARYS = ARRAY[1..CMAX] OF REAL;
ARY2 = ARRAY[1..RMAX, 1..CMAX] OF REAL;
ARY2S = ARRAY[1..RMAX, 1..CMAX] OF REAL;
VAR
Y : ARY;
G : ARYS;
X : ARY2;
A : ARY2S;
NROW,NCOL : INTEGER;
CH : CHAR;
PROCEDURE GET_DATA(VAR X : ARY2;
VAR Y : ARY;
VAR NROW,NCOL : INTEGER);
(* Get values for NROW, NCOL, and arrays X, Y *)
VAR I,J : INTEGER;
BEGIN
NROW:=10;
NCOL:=10;
FOR I:=1 TO NROW DO
BEGIN
X[I,1]:=1;
FOR J:=2 TO NCOL DO
X[I,J]:=I*X[I,J-1];
Y[I]:=2*I
END
END; (* GET_DATA *)
PROCEDURE WRITE_DATA;
(* Print out the answers *)
VAR I,J : INTEGER;
BEGIN
WRITELN;
WRITELN(' X Y');
FOR I:=1 TO NROW DO
BEGIN
FOR J:=1 TO NCOL DO
WRITE(X[I,J]:9:1,' ');
WRITELN(':',Y[I]:9:1)
END;
WRITELN;
WRITELN(' A G');
FOR I:=1 TO NCOL DO
BEGIN
FOR J:=1 TO NCOL DO
WRITE(A[I,J]:10:1,' ');
WRITELN(':',G[I]:10:1)
END
END; (* WRITE_DATA *)
PROCEDURE SQUARE(X : ARY2;
Y : ARY;
VAR A : ARY2S;
VAR G : ARYS;
NROW,NCOL : INTEGER);
(* Matrix multiplication routine *)
(* A = transpose X times X *)
(* G = Y times X *)
VAR I,K,L : INTEGER;
BEGIN (* SQUARE *)
FOR K:=1 TO NCOL DO
BEGIN
FOR L:=1 TO K DO
BEGIN
A[K,L]:=0;
FOR I:=1 TO NROW DO
BEGIN
A[K,L]:=A[K,L]+X[I,L]*X[I,K];
IF K<>L THEN A[L,K]:=A[K,L]
END
END; (* L loop *)
G[K]:=0;
FOR I:=1 TO NROW DO
G[K]:=G[K]+Y[I]*X[I,K]
END (* K loop *)
END; (* SQUARE *)
BEGIN (* MAIN *)
GET_DATA(X,Y,NROW,NCOL);
WRITE('>>Press (CR) to begin calculations: ');
READLN(CH);
WRITE('>>Starting matrix inversion..');
SQUARE(X,Y,A,G,NROW,NCOL);
WRITELN('..all done!');
WRITE_DATA
END.